// components/curriculum/curriculum.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    courses: [],
    colorArrays: ["#85B8CF", "#90C652", "#D8AA5A", "#FC9F9D", "#0A9A84", "#61BC69", "#12AEF3", "#E29AAD"],
    curWeek: 17
  },

  /**
   * 组件的方法列表
   */
  ready: function () {
    // 在组件布局完成后执行，此时可以获取节点信息
    this.getCourse();
  },
  methods: {
    getCourse: function () {
      var sid = app.globalData.sid;
      // var sid=1743205000113;
      var curWeek = this.data.curWeek
      var that = this
      wx.request({
        url: 'https://smart.songblog.top/getCourse',
        data: { sid, curWeek },
        header: { 'content-type': 'application/json' },
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: (result) => {
          console.log(result);
          that.setData({
            courses: result.data,
          })

        },
        fail: () => { },
        complete: () => { }
      });

    },
    subWeek: function () {

      this.setData({
        curWeek: this.data.curWeek - 1
      })
      var sid = app.globalData.sid;
      // var sid=1743205000113;
      var curWeek = this.data.curWeek
      var that = this
      wx.request({
        url: 'https://smart.songblog.top/getCourse',
        data: { sid, curWeek },
        header: { 'content-type': 'application/json' },
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: (result) => {
          console.log(result);
          that.setData({
            courses: result.data,
          })

        },
        fail: () => { },
        complete: () => { }
      });
    },

    addWeek: function () {

      this.setData({
        curWeek: this.data.curWeek + 1
      })
      var sid = app.globalData.sid;
      // var sid=1743205000113;
      var curWeek = this.data.curWeek
      var that = this
      wx.request({
        url: 'https://smart.songblog.top/getCourse',
        data: { sid, curWeek },
        header: { 'content-type': 'application/json' },
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: (result) => {
          console.log(result);
          that.setData({
            courses: result.data,
          })

        },
        fail: () => { },
        complete: () => { }
      });
    }
  }
})
